package com.hifar.test.collectdata.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hifar.common.QueryParamBean;
import com.hifar.sys.BusiResponse;
import com.hifar.sys.PageResult;
import com.hifar.sys.SystemUtil;
import com.hifar.test.collectdata.pojo.HfEnvDynamicsEquipRecord;
import com.hifar.test.collectdata.pojo.VO.DynamicsEquipRecordQueryParamVO;
import com.hifar.test.collectdata.service.IHfEnvDynamicsEquipRecordService;
import com.hifar.validate.CreateGroup;
import com.hifar.validate.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhuWeiWei
 * @description 力学设备运行记录
 * @date 2025/4/9 10:46
 */
@RestController
@RequestMapping("/api/busi/test/envDynamicsEquipRecord")
@Api("力学设备运行记录")
public class HfEnvDynamicsEquipRecordController {

    @Autowired
    private IHfEnvDynamicsEquipRecordService dynamicsEquipRecordService;


    @PostMapping("/add")
    @ApiOperation("新增")
    public BusiResponse add(@RequestBody @Validated(CreateGroup.class) HfEnvDynamicsEquipRecord hfEnvDynamicsEquipRecord) {
        dynamicsEquipRecordService.save(hfEnvDynamicsEquipRecord);
        return BusiResponse.OK();
    }

    @PostMapping("/edit")
    @ApiOperation("编辑")
    public BusiResponse edit(@RequestBody @Validated(UpdateGroup.class) HfEnvDynamicsEquipRecord hfEnvDynamicsEquipRecord) {
        dynamicsEquipRecordService.updateById(hfEnvDynamicsEquipRecord);
        return BusiResponse.OK();
    }


    @PostMapping("/listPage")
    @ApiOperation("分页查询")
    public BusiResponse listPage(@RequestBody @Validated DynamicsEquipRecordQueryParamVO queryParamsVO) {
        QueryParamBean queryParamBean = new QueryParamBean<>(queryParamsVO, HfEnvDynamicsEquipRecord.class);

        String equipId = queryParamsVO.getEquipId();
        QueryWrapper<HfEnvDynamicsEquipRecord> queryWrapper = queryParamBean.getQueryWrapper();
        queryWrapper.eq("equip_id", equipId);

        Page<HfEnvDynamicsEquipRecord> page = queryParamBean.getPage();

        Page<HfEnvDynamicsEquipRecord> pageData = dynamicsEquipRecordService.page(page, queryWrapper);
        PageResult pageResult = SystemUtil.parsePage(page, pageData);
        return BusiResponse.OK(pageResult);
    }


    @PostMapping("/delete")
    @ApiModelProperty("删除")
    public BusiResponse delete(@RequestBody List<String> idList) {
        dynamicsEquipRecordService.removeByIds(idList);
        return BusiResponse.OK();
    }


}
